Telegram Group & Telegram Channel
Your best companion in learning asyncio is asyncio.sleep. It works like time.sleep making the calling code wait the given number of seconds. This is the simplest example of an IO-bound task because while sleeping, your code literally does nothing but wait. And unlike time.sleep, asyncio.sleep is async. That means, while the calling task waits for it to finish, another task can be executed.

import asyncio
import time

async def main():
start = time.time()
await asyncio.sleep(2)
return int(time.time() - start)

asyncio.run(main())
# 2


You can't yet see how the code switches to another task while waiting because we have only one task. But bear with me, in the next posts we'll get to it.



tg-me.com/pythonetc/722
Create:
Last Update:

Your best companion in learning asyncio is asyncio.sleep. It works like time.sleep making the calling code wait the given number of seconds. This is the simplest example of an IO-bound task because while sleeping, your code literally does nothing but wait. And unlike time.sleep, asyncio.sleep is async. That means, while the calling task waits for it to finish, another task can be executed.

import asyncio
import time

async def main():
start = time.time()
await asyncio.sleep(2)
return int(time.time() - start)

asyncio.run(main())
# 2


You can't yet see how the code switches to another task while waiting because we have only one task. But bear with me, in the next posts we'll get to it.

BY Python etc


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 280

Share with your friend now:
tg-me.com/pythonetc/722

View MORE
Open in Telegram


Python etc Telegram | DID YOU KNOW?

Date: |

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

A Telegram spokesman declined to comment on the bond issue or the amount of the debt the company has due. The spokesman said Telegram’s equipment and bandwidth costs are growing because it has consistently posted more than 40% year-to-year growth in users.

Python etc from cn


Telegram Python etc
FROM USA